package com.suray.basic.wcs.utils;


import java.util.Objects;

/**
 * ClassName: Coord
 *
 * @author coop
 * @Description: 坐标
 */
public class Coord {

    private int x;
    private int y;
    private int z;

    public Coord() {
    }

    public Coord(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Coord(Coord sourceNode) {
        this.x = sourceNode.x;
        this.y = sourceNode.y;
        this.z = sourceNode.z;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null) {
            return false;
        }
        Coord coord = (Coord) o;
        return x == coord.x && y == coord.y && z == coord.z;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y, z);
    }


    /**
     * 判断路径始末两点是否径直, 或为同一个点
     *
     * @param start 起点
     * @param end   终点
     * @return boolean
     */
    public static boolean isStraight(Coord start, Coord end) {
        int samePoint = 0;
        if (start.x == end.x) {
            samePoint++;
        }
        if (start.y == end.y) {
            samePoint++;
        }
        if (start.z == end.z) {
            samePoint++;
        }
        return samePoint == 2 || samePoint == 3;
    }


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getZ() {
        return z;
    }

    public void setZ(int z) {
        this.z = z;
    }

    @Override
    public String toString() {
        return "(" + x + "," + y + "," + z +")";

    }

}
